<?php
// +----------------------------------------------------------------------
// | 火凤凰CMS内容管理系统
// +----------------------------------------------------------------------
// | Copyright (c) 2015~2018 http://cxbs.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 赵志广 <amdin@cxbs.net>
// +----------------------------------------------------------------------
namespace app\api\controller;

use app\common\controller\Apibase;
use app\common\model\Chinacode as cxModel;

class Chinacode extends Apibase {
    /**
     *  接收2个参数  zoneid  和 class
     */
    public function index(){
        $data = input('post.');
        $data = datatrim($data);
        switch ($data['class']){
            case 'don':
                $resdata = $this->get_don($data['zoneid']);
                break;
            case 'this':
                $resdata = $this->get_this($data['zoneid']);
                break;
        }
        return json($resdata);
    }

    /**
     * @param $zoneid 接收zoneid
     * @return mixed 返回下级地区列表，如果不存在，则返回0
     */
    public function get_don($zoneid){
        $cxmodel = new cxModel();
        $codelist['dondata'] = $cxmodel->get_don($zoneid);
        $codelist['code'] = '0';
        if(!empty($codelist['dondata']) && isset($codelist['dondata'])){
            $codelist['code'] = '1';
        }
        return $codelist;
    }
    /**
     * @param $zoneid 接收zoneid
     * @return mixed 返回本级地区列表，如果不存在，则返回0
     */
    public function get_this($zoneid){
        $cxmodel = new cxModel();
        $codelist['dondata'] = $cxmodel->get_this($zoneid);
        $codelist['code'] = '0';
        if(!empty($codelist['dondata']) && isset($codelist['dondata'])){
            $codelist['code'] = '1';
        }
        return $codelist;
    }
}
